<template>
  <div class="page-container-padding">
    <div>
      <div style="margin-bottom:10px;font-size:16px;color:#1386D2;">品种日报基本信息设置：</div>
      <div style="width:550px;">
        <el-form label-width="90px">
          <el-form-item label="品种" :model="basicObj">
            <el-select v-model="basicObj.variety_en" size="mini" style="width:100%;" @change="toQueryReportBasic">
              <el-option v-for="v in varietyList" :value="v.variety_en" :label="v.variety_long_name" :key="v.variety_en"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="撰写人">
            <el-input v-model="basicObj.author" placeholder="日报的撰写人" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="从业证号">
            <el-input v-model="basicObj.certificate1" placeholder="日报的作者从业证号" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="投资咨询号">
            <el-input v-model="basicObj.certificate2" placeholder="日报的作者投资咨询号" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="basicObj.note" placeholder="备注" size="mini"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="toSaveReportBasic">确定保存</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
let NAME_SPACE = 'V01'
import { getUserAuthVariety } from '@/api/operations/variety'
import { saveDailyReportBasic, getDailyReportBasic } from '@/api/regularReport/dailyReport'

export default {
  data(){
    return {
      varietyList: [

      ],
      basicObj: {
        variety_en: null,
        author: '',
        certificate1: '',
        certificate2: '',
        note: ''
      }
    }
  },
  mounted() {
    getUserAuthVariety({space: NAME_SPACE}).then(res => {
      this.varietyList = res.data
    })
  },
  methods:{
    toSaveReportBasic(){
      saveDailyReportBasic(this.basicObj).then(res => {
        this.$baseMessage(res.msg, res.code===200?'success':'error')
      })
    },

    toQueryReportBasic(varietyEN){
      getDailyReportBasic({v: varietyEN}).then(res => {
        const data = res.data
        if (data){
          this.basicObj.author = data.author
          this.basicObj.certificate1 = data.certificate1
          this.basicObj.certificate2 = data.certificate2
          this.basicObj.note = data.note
        }else{
          this.basicObj.variety_en = null
          this.basicObj.author = ''
          this.basicObj.certificate1 = ''
          this.basicObj.certificate2 = ''
          this.basicObj.note = ''
        }
      })
    }
  }
}
</script>

<style>
</style>
